import {getImageMD5Sync} from "./Uitls";
import * as fs from 'fs'

export class ImageEntity {
    name: string
    path: string
    md5: string
    base64: string
    get nameWithoutExt(): string {
        let comp = this.name.split('.')
        return comp.length === 2 ? comp[0] : ''
    }
    imgToBase64() {
        const data = fs.readFileSync(this.path);
        return `data:image/${this.path.split('.').pop()};base64,${data.toString('base64')}`;
    }
    constructor(name: string, path: string) {
        this.name = name
        this.path = path
        this.md5 = getImageMD5Sync(path)
        this.base64 = this.imgToBase64()
    }
}
